package com.tff.gmall.manger.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.tff.gmall.beans.PmsBaseAttrInfo;
import com.tff.gmall.beans.PmsBaseAttrValue;
import com.tff.gmall.beans.PmsBaseSaleAttr;
import com.tff.gmall.beans.PmsProductSaleAttr;
import com.tff.gmall.service.PmsBaseAttrInfoService;
import com.tff.gmall.service.SpuService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@CrossOrigin
public class AttrControllrt {

    @Reference
    private PmsBaseAttrInfoService attrInfoService;
    @Reference
    private SpuService spuService;

    /***
     * 获取平台属性列表
     * @return
     */
    @RequestMapping(value = "/attrInfoList")
    @ResponseBody
    public List<PmsBaseAttrInfo> attrInfoList(String catalog3Id) {
        return attrInfoService.attrInfoList(catalog3Id);
    }

    /***
     * 平台属性增加接口
     * @param pmsBaseAttrInfo
     * @param flag
     * @return
     */
    @RequestMapping(value = "/saveAttrInfo")
    @ResponseBody
    public Boolean saveAttrInfo(@RequestBody PmsBaseAttrInfo pmsBaseAttrInfo, Boolean flag) {

        System.out.println(pmsBaseAttrInfo.toString());
        return attrInfoService.saveAttrInfo(pmsBaseAttrInfo);
    }


    @RequestMapping(value = "/baseSaleAttrList")
    @ResponseBody
    public List<PmsBaseSaleAttr> baseSaleAttrList() {
        return attrInfoService.baseSaleAttrListService();
    }


    /***
     * 商品销售属性和属性值的查询
     * @param spuId
     * @return
     */
    @RequestMapping(value = "/spuSaleAttrList")
    @ResponseBody
    public List<PmsProductSaleAttr> spuSaleAttrList(String spuId) {
        List<PmsProductSaleAttr> pmsProductSaleAttrs = spuService.spuSaleAttrListService(spuId);
        return pmsProductSaleAttrs;
    }

    //平台属性的修改http://127.0.0.1:8081/getAttrValueList?attrId=12

    @RequestMapping(value = "/getAttrValueList")
    @ResponseBody
    public List<PmsBaseAttrValue> getAttrValueList(String attrId) {
        System.out.println(attrId);
        return attrInfoService.getPmsBaseAttrInfoByAttrid(attrId);
    }
}
